<template>
	<view class="work-container">
		<TopBar :tabBars="tabBars" :tabIndex="tabIndex" @change="onTabChange"></TopBar>
		<component ref="listRef" v-bind:is="currentTabComponent" :data="data"></component>
	</view>
</template>

<script>
	import stay from './stay.vue'
	import through from './through.vue'
	import TopBar from '@/components/top-bar/index.vue'
	
	export default {
		components: {
			TopBar,
			stay,
			through
		},
		computed: {
			currentTabComponent() {
				return this.tabBars.find((item) => item.index === this.tabIndex).componentName
			}
		},
		data() {
			return {
				tabBars: [{
						name: '待办',
						componentName: 'stay',
						index: 0
					},
					{
						name: '经办',
						componentName: 'through',
						index: 1
					}
				],
				tabIndex: 0,
				data: null
			}
		},
		// onPullDownRefresh() {
		// 	this.$refs.listRef.reloadData()
		// },
		// onReachBottom() {
		// 	this.$refs.listRef.getlist()
		// },
		mounted() {
			uni.$on('refresh', ()=>{
				this.$refs.listRef && this.$refs.listRef.getItemList()
			})
			
		},
		methods: {
			onTabChange(obj) {
				this.tabIndex = obj.index
			}
		}
	}
</script>

<style lang="scss" scoped></style>
